/*
 *  @product.title@
 *  Copyright (C) @product.copyright-year@
 *    @product.vendor@
 *    Registration Number: @product.registration-number@
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package jp.go.aist.six.util.search;



/**
 * The Relation represents a type of property-value relation
 * in search queries.
 *
 * <p>Each relation has an <em>operator</em> representation.
 * The symbol, say "=",  is the operator of the EQUAL relation.
 * </p>
 *
 * @author  Akihito Nakamura, AIST
 * @version $Id: Relation.java 300 2011-03-02 05:45:46Z nakamura5akihito $
 */
public enum Relation
{

    /**
     * EQUAL relation: "=".
     */
    EQUAL( "="  ),

    /**
     * NOT_EQUAL relation: "!=".
     */
    NOT_EQUAL( "!=" ),

    /**
     * LESS_THAN relation: "<".
     */
    LESS_THAN( "<"  ),

    /**
     * LESS_EQUAL relation: "<=".
     */
    LESS_EQUAL( "<=" ),

    /**
     * GREATER_THAN relation: ">".
     */
    GREATER_THAN( ">"  ),

     /**
      * GREATER_EQUAL relation: ">=".
      */
     GREATER_EQUAL( ">=" );



    /**
     * Returns a Relation with the specified name.
     *
     * @param   name
     *  the relation name.
     * @return
     *  the Relation object.
     * @throws  IllegalArgumetnException
     *  if the specified name is not defined.
     */
     public static Relation fromValue(
                     final String name
                     )
     {
         for (Relation  r : Relation.values()) {
             if (r.name().equals( name )) {
                 return r;
             }
         }

         throw new IllegalArgumentException( "invalid relation: " + name );
    }



    /**
     */
    private final String  _operator;



    /**
     * Constructs a relation type of the specified name.
     *
     * @param   name
     *  the name of this relation type.
     * @throws  IllegalArgumetnException
     *  if the specified name is not defined.
     */
    Relation(
                    final String operator
                    )
    {
        _operator = operator;
    }



    /**
     * Returns the operator of this relation type.
     *
     * @return
     *  the operator of this relation type.
     */
    public String operator()
    {
        return _operator;
    }



    //**************************************************************
    //  java.lang.Object
    //**************************************************************

//    /**
//     * Returns a string representation of this Relation.
//     *
//     * @return
//     *  a string representation of this Relation.
//     */
//    @Override
//    public String toString()
//    {
//        return name();
//    }

}
// Relation
